<template>
  <div class="inputa">
    <!-- 输入框 -->
    <div class="searchs-two">
      <router-link to="/classify" class="routera">
        <van-icon class="default-icon" name="arrow-left" />
      </router-link>
      <!-- <div @click="onSearch">搜索</div>
    <van-search  class="search" placeholder="" /> -->
      <van-search
        class="search-contents"
        left-icon=""
        v-model="value"
        right-icon="search"
        placeholder="请输入搜索关键词"
      />
      <!-- 切换样式风格 -->
      <van-icon @click="changeevent" style="font-size: 20px" name="wap-nav" />
      <!-- 筛选 -->
      <van-button type="primary" text="筛选" @click="chengeOverlayToShow" />
      <van-overlay :show="show">
        <div class="wrapper" @click.stop>
          <div class="block">
            <div class="priceSpace">
              <p>价格区间</p>
              <input type="text" v-model="min" placeholder="最低价" />
              <span>-----</span>
              <input type="text" v-model="max" placeholder="最高价" />
            </div>
            <div class="changButton">
              <button class="buttonTwo" @click="changeText">重置</button>
            <button class="buttonOne" @click="chengeOverlayToHide">确定</button>
            </div>
            
          </div>
        </div>
      </van-overlay>
    </div>

    <!-- 综合和新品 -->

    <van-tabs
      style="background-color: #f4f4f4"
      class="newsgoods"
      v-model:active="active"
      @change="goodsname"
    >
      <van-tab title="综合">
        <ul :class="iscol ? 'detail-total' : 'detail-two'">
          <li v-for="item in resData" :key="item.cat_id">
            <img :src="item.original_img" alt="" />
            <div class="total-detail">
              <p class="detail-span">{{ item.name }}</p>
              <p class="detail-spantwo">{{ item.shop_price_formated }}</p>
              <div class="stores">进店</div>
              <p style="color: grey; font-size: 14px">
                {{ item.sales_volume }}人已购买
              </p>
            </div>
          </li>
        </ul>
      </van-tab>
      <van-tab
        style="background-color: #f4f4f4"
        title="新品"
        @change="goodsname"
      >
        <ul :class="iscol ? 'detail-total' : 'detail-two'">
          <li v-for="item in resData" :key="item.cat_id">
            <img :src="item.original_img" alt="" />
            <div class="total-detail">
              <p class="detail-span">{{ item.name }}</p>
              <p class="detail-spantwo">{{ item.shop_price_formated }}</p>
              <div class="stores">进店</div>
              <p style="color: grey; font-size: 14px">
                {{ item.sales_volume }}人已购买
              </p>
            </div>
          </li>
        </ul>
      </van-tab>
      <!-- 销量：按照sort:sales_volume; -->
      <van-tab
        style="background-color: #f4f4f4"
        title="销量"
        @change="goodsname"
      >
        <ul :class="iscol ? 'detail-total' : 'detail-two'">
          <li v-for="item in resData" :key="item.cat_id">
            <img :src="item.original_img" alt="" />
            <div class="total-detail">
              <span class="detail-span">{{ item.name }}</span>
              <span class="detail-spantwo">{{ item.shop_price_formated }}</span>
              <div class="stores">进店</div>
              <span style="color: grey; font-size: 14px"
                >{{ item.sales_volume }}人已购买</span
              >
            </div>
          </li>
        </ul>
      </van-tab>
      <!-- 按照价格 -->
      <van-tab
        style="background-color: #f4f4f4"
        title="价格"
        @change="goodsname"
      >
        <ul :class="iscol ? 'detail-total' : 'detail-two'">
          <li v-for="item in resData" :key="item.cat_id">
            <img :src="item.original_img" alt="" />
            <div class="total-detail">
              <span class="detail-span">{{ item.name }}</span>
              <span class="detail-spantwo">{{ item.shop_price_formated }}</span>
              <div class="stores">进店</div>
              <span style="color: grey; font-size: 14px"
                >{{ item.sales_volume }}人已购买</span
              >
            </div>
          </li>
        </ul>
      </van-tab>
      <van-tab title="筛选">内容 4</van-tab>
    </van-tabs>
  </div>
</template>
<script>
// import { ref } from "vue";
export default {
  data() {
    // const active = ref(0);
    return {
      show: false,
      iscol: true,
      value: "",
      active: "",
      resData: "",
      min: "",
      max: "",
      list: ["goods_id", "last_update", "sales_volume", "shop_price"],
    };
  },
  mounted() {
    this.goodsname();
    //  this.goodscount(), this.goodsprice(), this.goodsupdate();
  },
  methods: {
    chengeOverlayToShow() {
      this.show = true;
      console.log(this.show);
    },
    chengeOverlayToHide(goods_id) {
      this.show = false;
      this.$store
        .dispatch({
          type: "detailclassify",
          min: this.min,
          max: this.max,
          cat_id: this.$route.params.id,
          sort: goods_id,
        })
        .then((data) => {
          this.resData = data;
        });
      // console.log(this.show);
    },
    changeText() {
      this.min = "";
      this.max = "";
    },
    changeevent() {
      this.iscol = !this.iscol;
    },
    goodsname(active) {
      this.$store
        .dispatch({
          type: "detailclassify",
          cat_id: this.$route.params.id,
          sort: this.list[active],
        })
        .then((data) => {
          this.resData = data;
        });
    },
    goodscount(active) {
      this.$store
        .dispatch({
          type: "detailclassify",
          cat_id: this.$route.params.id,
          sort: this.list[active],
        })
        .then((data) => {
          this.resData = data;
        });
    },
    // ,
    // goodsprice(active) {
    //   this.$store
    //     .dispatch({
    //       type: "detailclassify",
    //       cat_id: this.$route.params.id,
    //       sort: this.list[active],
    //     })
    //     .then((data) => {
    //       this.resData = data;
    //     });
    // },
    // goodsupdate(active) {
    //   this.$store
    //     .dispatch({
    //       type: "detailclassify",
    //       cat_id: this.$route.params.id,
    //       sort: this.list[active],
    //     })
    //     .then((data) => {
    //       this.resData = data;
    //     });
    // },

    // detailclassify() {
    //   this.$store
    //     .dispatch({
    //       type: "detailclassify",
    //       cat_id: this.$route.params.id,

    //     })
    //     .then((data) => {
    //       this.resData = data;
    //       // console.log(resData);
    //     });
    // },
  },
};
</script>

<style  lang="less">
* {
  margin: 0;
  padding: 0;
}
.inputa {
  .searchs-two {
    width: 100%;
    height: 60px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    .wrapper {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      height: 100%;
    }

    .block {
      width: 90%;
      height: 100%;
      background-color: #f4f4f4;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
    
      .priceSpace {
        width: 100%;
        height: 30%;
        background-color: #fff;
        p {
          font-size: 20px;
          margin-bottom: 20px;
        }
        input {
          width: 43%;
          height: 17%;
          border: 1px solid #F2F2F2;
          background-color: #F2F2F2;
          border-radius: 15px;
          color: #757575;
          text-align: center;
        }
      }
      .changButton{
        display: flex;
        justify-content: space-around;
        align-items:center ;
        width: 100%;
        height:60px;
        background-color: #fff;
.buttonOne {
        width: 120px;
        height: 40px;
        background-color: red;
        border-radius: 20px;
        font-size: 20px;
        color: #fff;
        outline: none;
        border: 1px solid red;
        // outline-color: red;
        text-align: center;
        line-height: 40px;
        margin-left: 30px;
      }
      .buttonTwo {
        width: 120px;
        height: 40px;
        background-color: #fff;
        border-radius: 20px;
        font-size: 20px;
        color: red;
        outline: none;
        border: 1px solid red;
        // outline-color: red;
        text-align: center;
        line-height: 40px;
      }
      }
      
    }
  }
  .default-icon {
    font-size: 30px;
    color: #999;
  }

  .search {
    font-size: 20px;
  }
  .search-contents {
    width: 75%;
    height: 35px;
  }
  .van-field__right-icon .van-icon {
    font-size: 20px;
  }
  .van-field__control {
    background-color: #fff;
  }
  .van-search__content {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 15px;
  }
  .detail-two {
    width: 100%;
    height: 100%;
    // margin: 0 auto;
    // background-color: #f4f4f4;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    // align-items:;
    li {
      width: 95%;
      height: 30%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      background-color: #fff;
      margin-top: 5px;
      img {
        width: 20%;
        height: 20%;
      }
      .total-detail {
        width: 60%;
        height: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        justify-content: center;
        flex-direction: column;

        .detail-span {
          font-size: 14px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          overflow: hidden;
          text-overflow: ellipsis;
          -webkit-line-clamp: 2;
          margin-bottom: 5px;
          margin-top: 5px;
        }
        .detail-spantwo {
          color: red;
          font-size: 14px;
          margin-bottom: 5px;
          margin-top: 5px;
        }
        .stores {
          width: 40px;
          height: 20px;
          background-color: red;
          color: #fff;
          font-size: 12px;
          text-align: center;
          margin-bottom: 5px;
          margin-top: 5px;
        }
      }
    }
  }
  .detail-total {
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    
    li {
      width: 45%;
      height: 30%;
      display: flex;
      flex-direction: column;
      //   align-items: center;
      justify-content: space-between;
      padding: 5px;
      text-align: left;
      margin-right: 3px;
      margin-left: 3px;
      //   border: 1px solid red;
      background-color: #fff;
      margin-top: 5px;
      img {
        width: 90%;
        height: 82%;
        margin-bottom: 5px;
      }
      .detail-span {
        font-size: 14px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        margin-bottom: 5px;
        margin-top: 5px;
      }
      .detail-spantwo {
        color: red;
        font-size: 14px;
        margin-bottom: 5px;
        margin-top: 5px;
      }
      .stores {
        width: 40px;
        height: 20px;
        background-color: red;
        color: #fff;
        font-size: 12px;
        text-align: center;
        margin-bottom: 5px;
        margin-top: 5px;
      }
    }
  }
}
</style>
